<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<title>新增地址</title>
		<link rel="stylesheet" href="//at.alicdn.com/t/font_604979_ninvlbwinz71ra4i.css" />
		<link rel="stylesheet" type="text/css" href="$!rc.contextPath/common/common.css"/>
		<link rel="stylesheet" href="$!rc.contextPath/common/picker.css" />
		<link rel="stylesheet" type="text/css" href="$!rc.contextPath/css/addressmanage1.css"/>
	</head>
	<body>
		<!--头-->
		<div class="title text-center">
			<a onClick="javascript:window.history.go(-1)"><</a>
			新增地址
			<div class="save-btn" onclick="f_save()">保存</div>
		</div>
		<!--主体-->
		<article>
			<form>
				<ul>
					<li>
						<strong>收货人</strong><input type="text" id="deliveryReceiver">
					</li>
					<li>
						<strong>手机号</strong><input type="number" maxlength="11" id="deliveryMobile">
					</li>
					<li onclick="picker()">
						<strong>所在城市</strong>
						<div >
							<span id="cityName">选择省市</span>
							<i class="iconfont icon-arrow-right-copy-copy-copy"></i>
						</div>
					</li>
					<li>
						<strong>区县街道</strong>
						<div>
							<span id="addrName">选择区县街道</span>
							<i class="iconfont icon-arrow-right-copy-copy-copy"></i>
						</div>
					</li>
					<li>
						<input type="text" value="" placeholder="请输入详细地址" id="deliveryAddress">
					</li>
					<li>
						<strong>设为默认地址</strong>
						<input type="checkbox" id="isDefault" />
					</li>
				</ul>
			</form>
		</article>
		
	</body>
	<script src="$!rc.contextPath/common/jquery-1.8.3.min.js" type="text/javascript"></script>
	<script src="$!rc.contextPath/common/picker.js"></script>
	<script type="text/javascript" src="$!rc.contextPath/js/addr.js"></script>
	<script type="text/javascript">
		var isDefault = 'N';
		function f_save(){
			
			var deliveryReceiver = $("#deliveryReceiver").val();
			var deliveryMobile = $("#deliveryMobile").val();
			var deliveryAddress = $("#cityName").text() + "-" + $("#addrName").text() + "-" + $("#deliveryAddress").val();
			
			if(deliveryReceiver == null || deliveryReceiver == ''){
				alert("请输入收货人信息");
				return false;
			}
			
			if(deliveryMobile == null || deliveryMobile == ''){
				alert("请输入收货人手机号");
				return false;
			}
			
			if(cityId == 0){
				alert("请选择所在城市");
				return false;
			}
			
			if(countyId == 0){
				alert("请选择区县街道");
				return false;
			}
			
			if($("#deliveryAddress").val() == null || $("#deliveryAddress").val() == ''){
				alert("请输入详细地址/门牌号");
				return false;
			}
			
			if($("#isDefault").attr("checked")){
				isDefault = 'Y';
			};
			
			$.ajax({
				"type": "POST",
				"url" : "$!rc.contextPath/member/addAddr",
				"dataType" : "json",
				"async":false,
				"data" : {
					provinceId : provinceId,
					cityId : provinceId,
					areaId : countyId,
					deliveryReceiver : deliveryReceiver,
					deliveryMobile : deliveryMobile,
					deliveryAddress : deliveryAddress,
					isDefault : isDefault
				},
				"success":function(data){
					if(data.code == '0'){
						self.location=document.referrer;
					}else{
						alert(data.text)
					}
				}	
			})
		}
	</script>
</html>
